package controllers;

import models.Person;

import org.springframework.beans.factory.annotation.Autowired;

import play.data.Form;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
import services.PersonService;
import views.html.*;

@org.springframework.stereotype.Controller
public class PersonController extends Controller {
	
	@Autowired
    private PersonService personService;
	
	public Result addPerson() {
    	return ok(addPerson.render(Form.form(Person.class)));
    }
    
    public Result savePerson() {
        Form<Person> form = Form.form(Person.class).bindFromRequest();
        Person person = form.get();
        personService.addPerson(person);
        return redirect(routes.Application.indexSegurosMoran());
    }
    
    public Result listPersons() {
        return play.mvc.Controller.ok(Json.toJson(personService.getAllPersons()));
    }
	
	

}
